package com.tentact.servlets;

import com.tentact.service.EmployeeService;

import com.tentact.vo.Employee;


import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "insertEmpServlet", value = "/insertEmpServlet")
public class insertEmpServlet extends HttpServlet {
    EmployeeService service =new EmployeeService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("进入注册servlet");
        String employeename =request.getParameter("employeename");
        String accountname =request.getParameter("accountname");
        //密码和确认密码
        String password =request.getParameter("password");
        String confirm =request.getParameter("confirm");

        int dept =Integer.parseInt(request.getParameter("department"));
        String phone =request.getParameter("phone");
        String email =request.getParameter("email");

        System.out.println(employeename);
        System.out.println(accountname);
        System.out.println(password);
        System.out.println(confirm);
        System.out.println(dept);
        System.out.println(phone);
        System.out.println(email);


        Employee emp =new Employee(employeename,accountname,password,phone, email,dept);

        if(service.insertEmp(emp)!=1){
            System.out.println("注册失败");
            String msg ="注册失败";
            request.setAttribute("msg",msg);
            request.getRequestDispatcher("register.jsp").forward(request,response);

        }else {
            System.out.println("注册成功");
            String msg ="注册成功";
            request.setAttribute("msg",msg);
            request.getRequestDispatcher("register.jsp").forward(request,response);
        }




    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}